#ifndef REGISTERDIALOG_H
#define REGISTERDIALOG_H

#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>
#include "Functionality/functionalityFactory.h"

#include <bits/random.h>

class registerDialog : public QDialog
{
    Q_OBJECT
public:
    explicit registerDialog(QDialog *parent = nullptr);

signals:

private:
    void addPhoneLayout();
    void addPasswdLayout(QLineEdit *passwdLineEditor, QString Text);
    void addVerificationCode();
    QImage generateVerificationCode();
    int randomValue();
    bool isValidPhoneNumber(const QString &phoneNumber);
    void addRegsiterBtn();
    void bindConnect();
    void ResetVerificationCode();
protected slots:
    void onRegisterBtnClicked();
    void onregistraSuccessed(QString data);
    void onregistraFailed(QString data);

private:
    QVBoxLayout *mainLayout;
    QLineEdit *phoneNumberlineEditor;
    QLineEdit *passwdLineEditor1;
    QLineEdit *passwdLineEditor2;
    QHBoxLayout *HLayout2; //为什么需要移到这里来呢，是因为我需要重设验证码
    QLabel *labelCode;
    QLineEdit *verificationCodeLineEditor;
    std::random_device rd;                               //随机种子
    std::mt19937 generator;                              //随机数生成器
    std::uniform_int_distribution<> distribution{0, 61}; //定义0-51的均匀分布
    QString rawCodeText; //这是原始的验证码，需要和输入的进行比较的
    QPushButton *registerBtn;

    //定义是个bool值用来判断是否输入使用完成，输入完成注册按钮才启用
    bool phone;
    bool passwd1;
    bool passwd2;
    bool code;

    std::shared_ptr<FunctionalityFactory> factory; //这是创建注册功能的工厂
    std::shared_ptr<FunctionalityInterface> Functionality;
};

#endif // REGISTERDIALOG_H
